<%--
  Created by IntelliJ IDEA.
  User: dengdc
  Date: 2017/7/19
  Time: 17:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<html>
<head>
    <title>diyishou </title>
    <jsp:include page="../../head.jsp"/>
    <script type="text/javascript">
        //
        <!--业务编码、集装箱号、合同协议号、提运单号、进出口类型、收发货人、供应商、下单人-->
        var formSetting = {
            title: "查询信息",
            module: 'query',
            columns: [
                {
                    name: "jobName",
                    label: "名称"
                }, {
                    name: "description",
                    label: "关键字"
                }],
            buttons: {
                custom: [{
                    id: "updatebtn0",
                    value: "新增",
                    click: function () {
                        clearForm();

                        layer.open({
                                       type: 1,
                                       area: ['600px', '400px'],
                                       title: '新增调度',
                                       maxmin: true, //开启最大化最小化按钮
                                       content: $("#winContent"),
                                       btn: ['确定', '关闭'],
                                       yes: function (index, layero) {
                                           var param = {};
                                           param.jobId = $('#jobId').val();
                                           param.jobName = $('#jobName').val();
                                           param.jobGroup = $('#jobGroup').val();
                                           param.cronExpression = $('#cronExpression').val();
                                           param.beanClass = $('#beanClass').val();
                                           param.jobStatus = $('#jobStatus').val();
                                           param.description = $('#description').val();
                                           var url = "/tSysJob/save";

                                           $.ajax({
                                                      type: "POST",
                                                      url: url,
                                                      data: param,
                                                      success: function (r) {
                                                          if (r.error_code == 0) {
                                                              $("#tSysJob").trigger("reloadGrid");
                                                          } else {
                                                              alert(r.msg);
                                                          }
                                                          layer.closeAll();
                                                      }
                                                  });
                                       },
                                       cancel: function (index) {
                                           clearForm();
                                       }
                                   });
                    }
                },
                    {
                        id: "updatebtn1",
                        value: "修改",
                        click: function () {
                            var id = getSelectedRowById('tSysJob');
                            if (id == null) {
                                return;
                            }
                            var row = $("#tSysJob").getRowData(id);

                            var stateStr = "";
                            if (row.jobStatus == "运行") {
                                stateStr = "1";
                            } else {
                                stateStr = "0";
                            }

                            $('#jobId').val(row.jobId);
                            $('#jobName').val(row.jobName);
                            $('#jobGroup').val(row.jobGroup);
                            $('#cronExpression').val(row.cronExpression);
                            $('#beanClass').val(row.beanClass);
                            $('#jobStatus').val(stateStr);
                            $('#description').val(row.description);

                            layer.open({
                                           type: 1,
                                           area: ['600px', '400px'],
                                           title: '修改调度',
                                           maxmin: true, //开启最大化最小化按钮
                                           content: $("#winContent"),
                                           btn: ['确定', '关闭'],
                                           yes: function (index, layero) {
                                               var param = {};
                                               param.jobId = $('#jobId').val();
                                               param.jobName = $('#jobName').val();
                                               param.jobGroup = $('#jobGroup').val();
                                               param.cronExpression = $('#cronExpression').val();
                                               param.beanClass = $('#beanClass').val();
                                               param.jobStatus = $('#jobStatus').val();
                                               param.description = $('#description').val();
                                               var url = "/tSysJob/update";

                                               $.ajax({
                                                          type: "POST",
                                                          url: url,
                                                          data: param,
                                                          success: function (r) {
                                                              if (r.error_code == 0) {
                                                                  $("#tSysJob")
                                                                      .trigger("reloadGrid");
                                                              } else {
                                                                  alert(r.msg);
                                                              }
                                                              layer.closeAll();
                                                          }
                                                      });
                                           },
                                           cancel: function (index) {
                                               clearForm();
                                           }
                                       });
                        }
                    },
                    {
                        id: "updatebtn2",
                        value: "删除",
                        click: function () {
                            var ids = getSels("tSysJob");
                            if (ids == null) {
                                return;
                            }

                            $.ajax({
                                       type: "POST",
                                       url: "/tSysJob/delete",
                                       contentType: "application/json",
                                       data: JSON.stringify(ids),
                                       success: function (r) {
                                           if (r.error_code == 0) {
                                               jw.alert("删除成功");
                                               $("#tSysJob").trigger("reloadGrid");
                                           } else {
                                               alert(r.msg);
                                           }
                                       }
                                   });
                        }
                    },
                    {
                        id: "updatebtnRun",
                        value: "添加调度",
                        click: function () {
                            var id = getSelectedRowById('tSysJob');
                            if (id == null) {
                                return;
                            }
                            var row = $("#tSysJob").getRowData(id);
                            var param = {};
                            param.jobId = row.jobId;
                            param.jobName = row.jobName;
                            param.jobGroup = row.jobGroup;
                            param.cronExpression = row.cronExpression;
                            param.beanClass = row.beanClass;
                            param.jobStatus = row.jobStatus;
                            param.description = row.description;
                            var url = "/tSysJob/add";

                            $.ajax({
                                       type: "POST",
                                       url: url,
                                       data: param,
                                       success: function (r) {
                                           if (r.error_code == 0) {
                                               jw.alert("添加成功");
                                           } else {
                                               alert(r.msg);
                                           }
                                       }
                                   });
                        }
                    },
                    {
                        id: "updatebtnStop",
                        value: "暂停",
                        click: function () {
                            var id = getSelectedRowById('tSysJob');
                            if (id == null) {
                                return;
                            }
                            var row = $("#tSysJob").getRowData(id);
                            var param = {};
                            param.jobId = row.jobId;
                            param.jobName = row.jobName;
                            param.jobGroup = row.jobGroup;
                            param.cronExpression = row.cronExpression;
                            param.beanClass = row.beanClass;
                            param.jobStatus = row.jobStatus;
                            param.description = row.description;
                            var url = "/tSysJob/pouse";

                            $.ajax({
                                       type: "POST",
                                       url: url,
                                       data: param,
                                       success: function (r) {
                                           if (r.error_code == 0) {
                                               jw.alert("暂停成功");
                                           } else {
                                               alert(r.msg);
                                           }
                                       }
                                   });
                        }
                    },
                    {
                        id: "updatebtnStop",
                        value: "恢复",
                        click: function () {
                            var id = getSelectedRowById('tSysJob');
                            if (id == null) {
                                return;
                            }
                            var row = $("#tSysJob").getRowData(id);
                            var param = {};
                            param.jobId = row.jobId;
                            param.jobName = row.jobName;
                            param.jobGroup = row.jobGroup;
                            param.cronExpression = row.cronExpression;
                            param.beanClass = row.beanClass;
                            param.jobStatus = row.jobStatus;
                            param.description = row.description;
                            var url = "/tSysJob/recover";

                            $.ajax({
                                       type: "POST",
                                       url: url,
                                       data: param,
                                       success: function (r) {
                                           if (r.error_code == 0) {
                                               jw.alert("恢复成功");
                                           } else {
                                               alert(r.msg);
                                           }
                                       }
                                   });
                        }
                    },
                    {
                        id: "updatebtnStop",
                        value: "取消",
                        click: function () {
                            var id = getSelectedRowById('tSysJob');
                            if (id == null) {
                                return;
                            }
                            var row = $("#tSysJob").getRowData(id);
                            var param = {};
                            param.jobId = row.jobId;
                            param.jobName = row.jobName;
                            param.jobGroup = row.jobGroup;
                            param.cronExpression = row.cronExpression;
                            param.beanClass = row.beanClass;
                            param.jobStatus = row.jobStatus;
                            param.description = row.description;
                            var url = "/tSysJob/cancle";

                            $.ajax({
                                       type: "POST",
                                       url: url,
                                       data: param,
                                       success: function (r) {
                                           if (r.error_code == 0) {
                                               jw.alert("取消成功");
                                           } else {
                                               alert(r.msg);
                                           }
                                       }
                                   });
                        }
                    },
                    {
                        id: "runOneTime",
                        value: "运行一次",
                        click: function () {
                            var id = getSelectedRowById('tSysJob');
                            if (id == null) {
                                return;
                            }
                            var row = $("#tSysJob").getRowData(id);
                            var param = {};
                            param.jobId = row.jobId;
                            param.jobName = row.jobName;
                            param.jobGroup = row.jobGroup;
                            param.cronExpression = row.cronExpression;
                            param.beanClass = row.beanClass;
                            param.jobStatus = row.jobStatus;
                            param.description = row.description;
                            var url = "/tSysJob/runOneTime";

                            $.ajax({
                                       type: "POST",
                                       url: url,
                                       data: param,
                                       success: function (r) {
                                           if (r.error_code == 0) {
                                               jw.alert("运行成功");
                                           } else {
                                               alert(r.msg);
                                           }
                                       }
                                   });
                        }
                    }, 
                    {
                        id: "pushBtn",
                        value: "发布",
                        click: function () {
                            var id = getSelectedRowById('tSysJob');
                            if (id == null) {
                                return;
                            }
                            var row = $("#tSysJob").getRowData(id);
                            var param = {};
                            param.jobId = row.jobId;
                            param.jobName = row.jobName;
                            param.jobGroup = row.jobGroup;
                            param.cronExpression = row.cronExpression;
                            param.beanClass = row.beanClass;
                            param.jobStatus = row.jobStatus;
                            param.description = row.description;
                            var url = "/tSysJob/push";

                            $.ajax({
                                       type: "POST",
                                       url: url,
                                       data: param,
                                       success: function (r) {
                   						if(r.error_code == 0){
                							alert('操作成功');
                						}else{
                							alert(r.msg);
                						}
                                       }
                                   });
                        }
                    },
                    {
                        id: "updatebtnTest",
                        value: "控制台",
                        click: function () {
                            location.href="/uncode/schedule";
                        }
                    }
                ]
            },
            grid: {
                id: "tSysJob",
                title: "查询结果",
                url: "/tSysJob/list",
                colModel: [{
                    index: "jobId",
                    name: "jobId",
                    key: true
                },
                    {
                        label: '状态', name: 'jobStatus', index: 'jobStatus',
                        formatter: function (value, options, row) {
                            if (value == "0") {//0 草稿， 1 生效， -1 无效
                                return "停止";
                            } else if (value == "1") {
                                return "运行";
                            }
                        }
                    },
                    {label: '运行状态', name: 'runningStatus', sortable: false},
                    {label: '名称', name: 'jobName', index: 'jobName'},
                    {label: '任务分组', name: 'jobGroup', index: 'jobGroup'},
                    {label: '表达式', name: 'cronExpression', index: 'cronExpression'},
                    {label: '方法名', name: 'beanClass', index: 'beanClass'},
                    {label: '描述', name: 'description', index: 'description'},
                    {label: '创建时间', name: 'createTime', index: 'createTime'},
                    {label: '更新时间', name: 'updateTime', index: 'updateTime'}],
                multiselect: true
            }
        };
        $(document).ready(function () {
            $("#table").mrdForm(formSetting);
            doResize();
            $(window).resize(function () {
                doResize();
            });

            $(".ui-jqgrid-title").text("调度列表");
        });

        function doResize() {
            var ss = getPageSize();
            $("#tSysJob").jqGrid('setGridHeight', ss.WinH - 240);
        }

        function getPageSize() {
            var winW, winH;
            if (window.innerHeight) {// all except IE
                winW = window.innerWidth;
                winH = window.innerHeight;
            } else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode
                winW = document.documentElement.clientWidth;
                winH = document.documentElement.clientHeight;
            } else if (document.body) { // other
                winW = document.body.clientWidth;
                winH = document.body.clientHeight;
            }
            return {WinW: winW, WinH: winH};
        }

        //选择多条记录
        function getSels(gridId) {
            var grid = $("#" + gridId);
            var rowKey = grid.getGridParam("selrow");
            if (!rowKey) {
                alert("请选择一条记录");
                return;
            }

            return grid.getGridParam("selarrrow");
        }

        //选择一条记录
        function getSelectedRowById(gridId) {
            var grid = $("#" + gridId);
            var rowKey = grid.getGridParam("selrow");
            if (!rowKey) {
                alert("请选择一条记录");
                return;
            }

            var selectedIDs = grid.getGridParam("selarrrow");
            if (selectedIDs.length > 1) {
                alert("只能选择一条记录");
                return;
            }

            return selectedIDs[0];
        }
        /**
         * 弹出窗口初始化
         * @author han
         **/
        function clearForm() {
            $('#jobId').val();
            $('#jobName').val();
            $('#jobGroup').val();
            $('#cronExpression').val();
            $('#beanClass').val();
            $('#jobStatus').val();
            $('#description').val();
        }
    </script>
</head>
<body>
<div id="table"></div>
<div id="winContent" style="display:none;margin:5px 5px 5px 5px;">
    <table width="100%" border="1" cellpadding="1" bordercolor="#eeeeee">
        <tr bgcolor="#FFFFFF">
            <td width="198" height="38" align="right" bgcolor="#f8f8f8">名称：</td>
            <td width="345" align="left">
                <input type="hidden" id="jobId" name="jobId">
                <input id="jobName" name="jobName" size="45"/>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td width="198" height="38" align="right" bgcolor="#f8f8f8">任务组：</td>
            <td width="345" align="left">
                <input id="jobGroup" name="jobGroup" size="45"/>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td width="198" height="38" align="right" bgcolor="#f8f8f8">表达式：</td>
            <td width="345" align="left">
                <input id="cronExpression" name="cronExpression" size="45"/>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td width="198" height="38" align="right" bgcolor="#f8f8f8">方法名：</td>
            <td width="345" align="left">
                <input id="beanClass" name="beanClass" size="45"/>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td align="right" height="38" bgcolor="#f8f8f8">状态：</td>
            <td align="left">
                <select id="jobStatus" name="jobStatus">
                    <option value="0">停用</option>
                    <option value="1">启用</option>
                </select>
            </td>
        </tr>
        <tr bgcolor="#FFFFFF">
            <td align="right" height="38" bgcolor="#f8f8f8">描述：</td>
            <td align="left">
                <textarea rows="5" cols="41" id="description" name="description"></textarea>
            </td>
        </tr>
    </table>
</div>
</body>
</html>
